package team.seekers.skill.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.seekers.skill.result.Result;
import team.seekers.skill.service.StatisticsDailyService;

import java.util.Map;

import static team.seekers.skill.result.ResultCode.ACTION_FAIL;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author cbj
 * @since 2021-02-08
 */
@RestController
@RequestMapping("/api/skill/statistics")
public class StatisticsDailyController {
    @Autowired
    private StatisticsDailyService dailyService;
    //用于统计各种数据
    @GetMapping("/statisticData/{day}")
    public Result statisticData(@PathVariable String day){
        boolean b = dailyService.statisticData(day);
        if(b)
            return Result.success();
        else
            return Result.fail(ACTION_FAIL).message("插入统计数据失败，请稍后重试");

    }
    //用于结合eCharts进行图表的显示，其中echarts官方要求前端数据为json数据形式
    //这里的type是统计因子，例如注册人数，技能的完成的人数
    @GetMapping("showData/{type}/{begin}/{end}")
    public Result showData(@PathVariable String type, @PathVariable String begin,
                           @PathVariable String end) {
        Map<String,Object> map = dailyService.getShowData(type,begin,end);
        return Result.success(map);
    }

}

